package com.buba.controller;

import com.buba.pojo.LoginLog;
import com.buba.pojo.Message;
import com.buba.pojo.Pagination;
import com.buba.service.LoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@CrossOrigin(allowCredentials = "true" , originPatterns = "*")
public class LoginLogController {
    @Autowired
    private LoginLogService loginLogService;

    @RequestMapping("/selLogging")
    public Pagination<LoginLog> selLogging(@RequestParam Map<String,Object> map){
        Pagination<LoginLog> pagination = new Pagination<>();
        pagination.setPageNow(Long.parseLong(map.get("pageNow")+""));
        pagination.setLimit(Long.parseLong(map.get("limit")+""));
        // 添加分页查询条件
        map.put("index",pagination.computeIndex());   // 添加当前页
        map.put("limit",pagination.getLimit());   // 添加每页条数
        pagination.setPageCount(loginLogService.selLogging(map));
        pagination.computePageTotal();
        pagination.setList(loginLogService.selLoggingList(map));
        return pagination;
    }

    @RequestMapping("/delLoginLog")
    public Message delLoginLog(@RequestParam("loginIds") String ids){
        long count = loginLogService.delLoginLog(ids);
        return new Message(1, "删除了" + count + "条数据");
    }
}
